﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace HuiZe.education.View.Ethan
{
    public class MediaTypeIconConverter2 : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                string _url = value.ToString();
                string _ex = Path.GetExtension(_url).Substring(1).ToLower();
                switch (_ex)
                {
                    case "pdf": _url = "pack://application:,,,/HuiZe.education;component/Ethan/Res/Images/MySpace/pdf.png"; break;
                    case "mp4": _url = "pack://application:,,,/HuiZe.education;component/Ethan/Res/Images/MySpace/mp4.png"; break;
                    case "doc": _url = "pack://application:,,,/HuiZe.education;component/Ethan/Res/Images/MySpace/doc.png"; break;
                    case "docx": _url = "pack://application:,,,/HuiZe.education;component/Ethan/Res/Images/MySpace/doc.png"; break;
                    case "mp3": _url = "pack://application:,,,/HuiZe.education;component/Ethan/Res/Images/MySpace/mp3.png"; break;
                    case "ppt": _url = "pack://application:,,,/HuiZe.education;component/Ethan/Res/Images/MySpace/ppt.png"; break;
                    case "pptx": _url = "pack://application:,,,/HuiZe.education;component/Ethan/Res/Images/MySpace/ppt.png"; break;
                    case "swf": _url = "pack://application:,,,/HuiZe.education;component/Ethan/Res/Images/MySpace/swf.png"; break;
                    case "txt": _url = "pack://application:,,,/HuiZe.education;component/Ethan/Res/Images/MySpace/txt.png"; break;
                    case "xls": _url = "pack://application:,,,/HuiZe.education;component/Ethan/Res/Images/MySpace/xls.png"; break;
                    case "xlsx": _url = "pack://application:,,,/HuiZe.education;component/Ethan/Res/Images/MySpace/xls.png"; break;
                    case "zip": _url = "pack://application:,,,/HuiZe.education;component/Ethan/Res/Images/MySpace/zip.png"; break;
                }

                if (!string.IsNullOrEmpty(_url))
                {
                    BitmapImage _bmp = new BitmapImage();
                    _bmp.CacheOption = BitmapCacheOption.OnLoad;
                    _bmp.BeginInit();
                    _bmp.UriSource = new Uri(_url, UriKind.RelativeOrAbsolute);
                    _bmp.EndInit();
                    return _bmp;
                }
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        string[] _ex_img = new string[]
        {
            "png", "jpg", "jpeg", "bmp", "gif"
        };
        string[] _ex_txt = new string[]
        {
            "txt"
        };
        string[] _ex_pdf = new string[]
        {
            "pdf"
        };
        string[] _ex_flash = new string[]
        {
            "swf"
        };
        string[] _ex_html = new string[]
        {
            "html"
        };
        string[] _ex_excel = new string[]
        {
            "xls", "xlsx"
        };
        string[] _ex_word = new string[]
        {
            "doc", "docx"
        };
        string[] _ex_ppt = new string[]
        {
            "ppt", "pptx"
        };
        string[] _ex_mp3 = new string[]
        {
            "aac", "ac3", "acm", "amr", "ape", "caf", "flac", "m4a", "mp3", "ra", "wav", "wma"
        };
        string[] _ex_video = new string[]
        {
            "3gp",
            "asf",
            "avi",
            "dat",
            "dv",
            "flv",
            "f4v",
            "gif",
            "m2t",
            "m3u8",
            "m4v",
            "mj2",
            "mjepg",
            "mkv",
            "mov",
            "mp4",
            "mpe",
            "mpg",
            "mpeg",
            "mts",
            "ogg",
            "qt",
            "rm",
            "rmab",
            "ts",
            "vob",
            "wmv",
            "webm",
        };
    }
}
